﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using POSSystem.DAL;

namespace POSSystem.BLL
{
    public class OrderItemCategory
    {
        public const int Product = 1;
        public const int BusinessCard = 2;
    }

    public class OrderItems : _OrderItems
    {
        public const string PRODUCT_NAME = "ProductName";
        public const string BAR_CODE = "BarCode";

        public override void AddNew()
        {
            base.AddNew();
            if(this.DataTable.Columns[PRODUCT_NAME] == null)
                this.AddColumn(PRODUCT_NAME, typeof(string));
            if (this.DataTable.Columns[BAR_CODE] == null)
                this.AddColumn(BAR_CODE, typeof(string));
        }

        public string ProductName
        {
            get
            {
                return this.GetColumn(PRODUCT_NAME).ToString();
            }
            set
            {
                this.SetColumn(PRODUCT_NAME, value);
            }
        }

        public string BarCode
        {
            get
            {
                return this.GetColumn(BAR_CODE).ToString();
            }
            set
            {
                this.SetColumn(BAR_CODE, value);
            }
        }


        public static OrderItems GetOrderItems(int orderID)
        {
            try
            {
                OrderItems items = new OrderItems();
                items.Where.OrderID.Value = orderID;
                items.Where.Deleted.Value = false;
                items.Query.Load();

                return items;
            }
            catch (Exception ex)
            {
                ErrorLog.WriteToFile("OrderItems.cs", "GetOrderItems", ex.StackTrace);
                throw ex;
            }
        }

        public static OrderItems GetOrderItemByIds(string ids)
        {
            try
            {
                OrderItems items = new OrderItems();
                items.Where.ID.Value = ids;
                items.Where.ID.Operator = MyGeneration.dOOdads.WhereParameter.Operand.In;
                items.Query.Load();

                return items;
            }
            catch (Exception ex)
            {
                ErrorLog.WriteToFile("OrderItems.cs", "GetOrderItems", ex.StackTrace);
                throw ex;
            }
        }
    }
}
